//
//  IGRequestHUB.m
//  jingdongfang
//
//  Created by BOE on 2017/8/29.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGRequestHUB.h"
#import "SVProgressHUD.h"

@interface IGRequestHUB()<YTKRequestAccessory>
@property (nonatomic, strong) UIActivityIndicatorView *activityView;
@end

static IGRequestHUB *_instance;
@implementation IGRequestHUB

+ (instancetype)shareIGRequestHUB {
    return [[self alloc] init];
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (_instance == nil) {
            _instance = [super allocWithZone:zone];
        }
    });
    return _instance;
}

//初始化方法
- (instancetype)init {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super init];
    });
    return _instance;
}

- (id)copyWithZone:(NSZone *)zone {
    return _instance;
}

- (id)mutableCopyWithZone:(NSZone *)zone {
    return _instance;
}

- (UIActivityIndicatorView *)activityView {
    if (!_activityView) {
        _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [_activityView startAnimating];
    }
    return _activityView;
}

#pragma mark - YTKRequestAccessory
- (void)requestWillStart:(id)request {
    [kKeyWindow addSubview:self.activityView];
    [_activityView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(kKeyWindow.mas_centerX);
        make.centerY.mas_equalTo(kKeyWindow.mas_centerY);
    }];
}

- (void)requestWillStop:(id)request {
    [self.activityView removeFromSuperview];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
